<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

/*********************************************************************************
 * SugarCRM is a customer relationship management program developed by
 * SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License version 3 as published by the
 * Free Software Foundation with the addition of the following permission added
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Affero General Public License along with
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 * 
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
 * 
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
 * technical reasons, the Appropriate Legal Notices must display the words
 * "Powered by SugarCRM".
 ********************************************************************************/
/*********************************************************************************

 * Description: This file is used to override the default Meta-data DetailView behavior
 * to provide customization specific to the edanz_Feedback module.
 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
 * All Rights Reserved.
 * Contributor(s): ______________________________________..
 ********************************************************************************/

require_once('include/MVC/View/views/view.detail.php');

class edanz_FeedbackViewDetail extends ViewDetail {

 	function edanz_FeedbackViewDetail(){
 		parent::ViewDetail();
 	}
 	
 	function display() {
 		global $app_list_strings, $current_user;
		require_once 'modules/edanz_Editor/edanz_Editor.php';
		$feedback_recipient = new edanz_Editor();
		$feedback_recipient->retrieve($this->bean->related_editor_id);

		require_once 'include/SugarEmailAddress/SugarEmailAddress.php'; 
		$sea = new SugarEmailAddress; 
		$to_email_addrs = $feedback_recipient->full_name . " <". $sea->getPrimaryAddress($feedback_recipient).">"; 
		$parent_id = $this->bean->id;
		$parent_type = $this->bean->module_dir;
		$subject = $app_list_strings['feedback_name_dom'][$this->bean->name]." - ".$this->bean->r2jobname_c;
		$composeData = "parent_id=".$parent_id."&parent_type=".$parent_type."&to_email_addrs=".$to_email_addrs."&subject=".$subject."&body=".html_entity_decode($this->bean->description,ENT_QUOTES);
		require_once('modules/Emails/EmailUI.php');
		$eUi = new EmailUI();
		$j_quickComposeOptions = htmlspecialchars($eUi->generateComposePackageForQuickCreateFromComposeUrl($composeData));

		$this->ss->assign("to_email", $sea->getPrimaryAddress($feedback_recipient));
		$this->ss->assign("to_cc", $this->bean->cc_c);
		$this->ss->assign("body", htmlspecialchars(nl2br($this->bean->description)));
		$this->ss->assign("Subject", $subject);
		$this->ss->assign("from", $current_user->email1);
		$this->ss->assign("fromName", $current_user->name);
		$this->ss->assign("parent_id", $parent_id);
		$this->ss->assign("parent_type", $parent_type);
		$this->ss->assign("attachment", $this->bean->attachment_c);
		$this->ss->assign("attachment_name", $this->bean->attachment_name_c);
		$this->ss->assign("errorInfo", $_REQUEST['ErrorInfo']);
		
		$this->ss->assign("QUICK_COMPOSE_OPTIONS", $j_quickComposeOptions);
		$this->ss->assign("DESCRIPTION_LENGTH", strlen($this->bean->description));
		$this->ss->assign("FEEDBACK_POINT_COUNT", count($this->bean->get_linked_beans('feedbackpoints','edanz_FeedbackPoint')));
		$this->ss->assign("EMAIL_COUNT", count($this->bean->get_linked_beans('emails','Email')));
 		
		if (isset($_REQUEST['return_module'])) $this->ss->assign("RETURN_MODULE", $_REQUEST['return_module']);
		if (isset($_REQUEST['return_action'])) $this->ss->assign("RETURN_ACTION", $_REQUEST['return_action']);
		if (isset($_REQUEST['return_id'])) $this->ss->assign("RETURN_ID", $_REQUEST['return_id']);
		
		parent::display();
 	}

    public function getModuleTitle(
        $show_help = true
        )
    {
        global $sugar_version, $sugar_flavor, $server_unique_key, $current_language, $action;

        $theTitle = "<div class='moduleTitle'>\n<h2>";

        $module = preg_replace("/ /","",$this->module);

        $params = $this->_getModuleTitleParams();
        $count = count($params);
        $index = 0;

                if(SugarThemeRegistry::current()->directionality == "rtl") {
                        $params = array_reverse($params);
                }

	for($i=0;$i<count($params);$i++)
		if($params[$i] == 'FishTest')
			$params[$i] = 'EditingTest';

        foreach($params as $parm){
            $index++;
            $theTitle .= $parm;
            if($index < $count){
                $theTitle .= $this->getBreadCrumbSymbol();
            }
        }
        $theTitle .= "</h2>\n";

        if ($show_help) {
            $theTitle .= "<span class='utils'>";

            $createImageURL = SugarThemeRegistry::current()->getImageURL('create-record.gif');
            $theTitle .= <<<EOHTML
&nbsp;
EOHTML;
        }

        $theTitle .= "</span></div>\n";
        return $theTitle;
    }
}
?>
